﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExpertSystem.Interfaces;

namespace ExpertSystem.Domains
{
    public abstract class Function : IFunction 
    {
        #region Implementation of IFunction

        private string _name;
        private List<IVariable> _variables;
        private string _discription;

        /// <summary>
        /// Имя функции
        /// </summary>
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// Переменные учавствующие в вычислении значения
        /// </summary>
        public List<IVariable> Variables
        {
            get { return _variables; }
            set { _variables = value; }
        }

        /// <summary>
        /// Выполнить вычисление функции
        /// </summary>
        /// <returns>Значение функции</returns>
        public abstract bool Calculate();
        

        public bool CanBeResolved()
        {
            return !_variables.Any(variable => !variable.CanBeResolved() && !variable.HaveValue());
        }

        /// <summary>
        /// Описание семантики функции
        /// </summary>
        public string Discription
        {
            get { return _discription; }
        }

        public bool CanBeCalculated()
        {
            return !_variables.Any(v => !v.HaveValue());
        }

        #endregion
    }
}
